package com.bigmodel.controller;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.RandomUtil;
import com.bigmodel.vo.RequestAmdbAttrVO;
import com.bigmodel.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/testv2")
public class TestV2Controller {

    /**
     * 数据库状态查询
     * @return
     */
    @PostMapping("/getDbStatus")
    public ResponseResult getDbStatus(@RequestBody List<String> nameList) {
        List<Map<String,String>> statusList = new ArrayList<>();
        for(String name : nameList){
            Map<String,String> map = new HashMap<>();
            map.put("name",name);
            map.put("status","error");
            statusList.add(map);
        }
        return  new ResponseResult().setData(statusList);
    }

    /**
     * 数据库重启
     * @return
     */
    @PostMapping(value = "/restartDb")
    public ResponseResult restartDb(@RequestBody List<String> nameList){
        String msg = "数据库重启成功";
        return  new ResponseResult().setMsg(msg);
    }


    /**
     * 应用实例状态查询
     * @return
     */
    @PostMapping("/getInstanceStatus")
    public ResponseResult getInstanceStatus(@RequestBody List<String> nameList) {
        long random = RandomUtil.randomLong(0, 2);

        List<Map<String,String>> statusList = new ArrayList<>();
        for(String name : nameList){
            Map<String,String> map = new HashMap<>();
            map.put("name",name);
            map.put("status","success");
            statusList.add(map);
        }
        return  new ResponseResult().setData(statusList);
    }


    /**
     * 应用实例状态查询
     * @return
     */
    @GetMapping("/findInstance")
    public ResponseResult findInstance(@RequestParam String systemName) {
        long random = RandomUtil.randomLong(1, 3);

        List<String> instanceList = new ArrayList<>();
        for(int i = 1 ; i <= random; i++){
            instanceList.add("实例"+i);
        }
        return  new ResponseResult().setData(instanceList);
    }

    @GetMapping("/findDb")
    public ResponseResult findDb(@RequestParam String systemName) {
        long random = RandomUtil.randomLong(1, 3);

        List<String> instanceList = new ArrayList<>();
        for(int i = 1 ; i <= random; i++){
            instanceList.add("数据库"+i);
        }
        return  new ResponseResult().setData(instanceList);
    }


    /**
     * 应用实例重启
     * @return
     */
    @PostMapping(value = "/restartInstance")
    public ResponseResult restartInstance(@RequestBody List<String> nameList){
        String msg = "应用实例重启成功";
        return  new ResponseResult().setMsg(msg);
    }










}
